// sub_trigger.cpp
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "std_msgs/Bool.h"

ros::Publisher trigger_pub;
bool already_triggered = false; // 用于记录是否已经发布过

void messageCallback(const std_msgs::String::ConstPtr& msg)
{
    if (!already_triggered && msg->data == "1")
    {
        ROS_INFO("接收成功: %s", msg->data.c_str());
        std_msgs::Bool trigger_msg;
        trigger_msg.data = true;
        trigger_pub.publish(trigger_msg);
        already_triggered = true; // 设置标志为 true，防止再次发布
    }
    else
    {
        ROS_INFO("接收失败或已触发过: %s", msg->data.c_str());
    }
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "sub_trigger");
    ros::NodeHandle nh;

    trigger_pub = nh.advertise<std_msgs::Bool>("/trigger_flight", 10);
    ros::Subscriber sub = nh.subscribe("/nlink_linktrack_nodeframe0", 10, messageCallback);

    ros::spin();
    return 0;
}